#include "FileTransfareWindow.h"
#include "../../core/Impp.h"


namespace Impp
{

BEGIN_EVENT_TABLE(FileTransfareInfoPanel, wxPanel)
  EVT_BUTTON(wxID_ANY,FileTransfareInfoPanel::onButton)
END_EVENT_TABLE()
;

FileTransfareInfoPanel::FileTransfareInfoPanel(wxWindow* parent,const ActionId & id) :
	wxPanel(parent),
	id(id)
{
	info = new wxStaticText(this,wxID_ANY,wxT("Incoming File"));
	btAccept = new wxButton(this,wxID_OK, wxT("Accept"));
	btCancle = new wxButton(this,wxID_CANCEL, wxT("Cancle"));
	
	wxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
	sizer->Add(info,1,wxEXPAND|wxALL,0);
	sizer->Add(btAccept,1,wxEXPAND|wxALL,0);
	sizer->Add(btCancle,1,wxEXPAND|wxALL,0);
	
	SetSizer(sizer);
}


FileTransfareInfoPanel::~FileTransfareInfoPanel()
{
}

void FileTransfareInfoPanel::onButton(wxCommandEvent & event)
{
	if(event.GetId() == wxID_OK || event.GetId() == wxID_CANCEL){
		Impp::exemplar()->processIncomingFileAccept(id, event.GetId() == wxID_OK);
	}
}

//-----------------------------------------------------------------------

FileTransfareWindow::FileTransfareWindow(wxFrame* parent) :
	wxFrame(parent,wxID_ANY,wxT("File Transfare"))
{
	sizer = new wxBoxSizer(wxVERTICAL);
	SetSizer(sizer);
	SetSize(600,400);
	Layout();
	CenterOnScreen();
	Show();
}


FileTransfareWindow::~FileTransfareWindow()
{
	std::vector<FileTransfareInfoPanel*>::iterator iter(transfares.begin()); 
	for (; iter != transfares.end(); ++iter){ 
		FileTransfareInfoPanel* info = *iter;
			delete info;
	}
}

void FileTransfareWindow::addFileTransfareInfo(FileTransfareEvent & event){
	
	ActionId id = event.getActionId();
	FileTransfareInfoPanel* info = new FileTransfareInfoPanel(this, id);
	transfares.push_back(info);
	sizer->Add(info);
	sizer->Layout();
	
}

}
